# encoding: utf-8
from datetime import datetime

from exts import db


class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    username = db.Column(db.VARCHAR(100), nullable=False)
    password = db.Column(db.VARCHAR(100), nullable=False, default='123456', server_default='123456')
    create_time = db.Column(db.DATETIME, nullable=False, default=datetime.now, server_default=db.func.now())
    modify_time = db.Column(db.DATETIME, nullable=False, default=datetime.now, server_default=db.func.now())


class BookSelf(db.Model):
    __tablename__ = 'book_self'
    bookId = db.Column(db.VARCHAR(100), nullable=False, default='', server_default='', primary_key=True)
    sourceId = db.Column(db.VARCHAR(100), nullable=False, default='', server_default='')
    title = db.Column(db.VARCHAR(255), nullable=False, default='', server_default='')
    author = db.Column(db.VARCHAR(255), nullable=False, default='', server_default='')
    cover = db.Column(db.VARCHAR(255), nullable=False, default='', server_default='')
    isInShelf = db.Column(db.Boolean, nullable=False, default=True)
    lastChapter = db.Column(db.VARCHAR(255), nullable=False, default='', server_default='')
    readChapter = db.Column(db.Integer, nullable=False, default=0)
    sort = db.Column(db.Boolean, nullable=False, default=False)
    updated = db.Column(db.VARCHAR(100), nullable=False, default='', server_default='')

    user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), nullable=False, primary_key=True)

    user = db.relationship('User', backref=db.backref('book_selves'))

